package org.jeecg.modules.appuser.service.impl;

import cn.hutool.core.util.RandomUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.jeecg.common.util.mall.HttpUtils;
import org.jeecg.modules.appuser.constant.GameUserShandwConstant;
import org.jeecg.modules.mall.entity.GameBean;
import org.springframework.util.DigestUtils;

import java.io.IOException;
import java.net.URLEncoder;
import java.util.Date;
import java.util.List;

public class ADVB {
    private static String channelNumer = "9022148b77d242778162c8f07a784307";


    public static void main(String[] args) {

        //      String url = "http://platform.shandw.com/getGameInfoList?channelId=13534&sec=\"+time+\"&sign=\"+this.$md5('13534'+time+'9022148b77d242778162c8f07a784307'";
       String user_id="123123123";
       String avatar="";
        test1(user_id,avatar);

    }

    private static void test1(String user_id,String avatar) {
        String url = "http://platform.shandw.com/getGameInfoList";

        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append(GameUserShandwConstant.URL);
        stringBuffer.append("?");
        //  stringBuffer.append("uid");
        //stringBuffer.append("="+user_id+"&");
        //  stringBuffer.append(GameUserShandwConstant.CHANNELID);
        String parma1 = "13534";
        stringBuffer.append("channelId=" + parma1);
        stringBuffer.append("&sec=");
        long param2 = System.currentTimeMillis();
        stringBuffer.append(param2);
        stringBuffer.append("&sign=");
        String md5str = DigestUtils.md5DigestAsHex((parma1 + param2 + channelNumer).getBytes());
        System.out.println("md5str-->" + md5str);
        stringBuffer.append(md5str);
        try {
            url = stringBuffer.toString();
            System.out.println("url-->" + url);
            String result = HttpUtils.httpClientGet(url, "");

            JSONObject jsonObject = JSON.parseObject(result);

            String contentlist = jsonObject.getString("list");
            List<GameBean> gameBeanList = JSON.parseArray(contentlist, GameBean.class);
            String iframe_url="";
            for (GameBean gameBean : gameBeanList) {
              System.out.println(gameBean.getUrl());
                iframe_url="http://www.shandw.com/mi/game/";
                iframe_url=iframe_url+gameBean.getId()+".html";
                iframe_url=iframe_url+"?uid="+user_id+"&channel="+parma1;
                iframe_url=iframe_url+"&appid="+gameBean.getId()+"&nick="+ URLEncoder.encode("口袋"+ RandomUtil.randomNumbers(10), "utf8");
                iframe_url=iframe_url+"&avatar="+avatar;
                long time = new Date().getTime() / 1000;
                iframe_url=iframe_url+"&time="+time;

               String sign = DigestUtils.md5DigestAsHex(("channel=" + parma1 + "&appid=" + gameBean.getId() + "&time=" + time + "&uid=" + user_id + channelNumer).getBytes());
                iframe_url=iframe_url+"&sign="+sign;
                gameBean.setIframeurl(iframe_url);
                iframe_url="";
            }

            System.out.println("\n\n\n");
            for (GameBean gameBean : gameBeanList) {
                System.out.println(gameBean.getId());
                System.out.println(gameBean.getIframeurl());
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
